<?php

namespace App\Http\Middleware;

use App\Http\Models\AdminUser;
use Closure;
use Illuminate\Support\Facades\Auth;

class RouteAuthMiddleware
{
    public function handle($request, Closure $next,$guard = null)
    {
        $user=AdminUser::find(auth('admin')->user()->id);
        if (!$user->hasRole($guard) && !$user->can($guard)) {
            echo header("content-type:text/html; charset=uft-8");
            echo "<div style='display: -webkit-flex;display: flex;flex-direction:column;justify-content:center;align-items:center;height:100%;'><h2>".trans('config.no_permission')."</h2><pre>
          .----.
       _.'__    `.
   .--($)($$)---/#\
 .' @          /###\
 :         ,   #####
  `-..__.-' _.-\###/
        `;_:    `\"'
      .'\"\"\"\"\"`.
     /,  ya  ,\\\
    //  err!   \\\
    `-._______.-'
    ___`. | .'___
   (______|______)
   </pre></div>";
            exit();
        }
        return $next($request);
    }
}
